-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable & pass dbt-adapter-tests #16
Conversation
{% macro sqlserver__drop_schema(relation) -%} | ||
{%- set tables_in_schema_query %} | ||
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES | ||
WHERE TABLE_SCHEMA = '{{ relation.schema }}' | ||
{% endset %} | ||
{% set tables_to_drop = run_query(tables_in_schema_query).columns[0].values() %} | ||
{% for table in tables_to_drop %} | ||
{%- set schema_relation = adapter.get_relation(database=relation.database, | ||
schema=relation.schema, | ||
identifier=table) -%} | ||
{% do drop_relation(schema_relation) %} | ||
{%- endfor %} | ||
|
||
{% call statement('drop_schema') -%} | ||
drop schema if exists {{ relation.without_identifier().schema }} | ||
IF EXISTS (SELECT * FROM sys.schemas WHERE name = '{{ relation.schema }}') | ||
BEGIN | ||
EXEC('DROP SCHEMA {{ relation.schema }}') | ||
END |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikaelene here is the change we made that @jtcohen6 mentioned here dbt-msft/dbt-sqlserver#54 (comment).
In our adapters we never use drop_schema()
, nor does dbt-integration-tests
so we never new it was problematic.
{% macro sqlserver__get_columns_in_query(select_sql) %} | ||
{% call statement('get_columns_in_query', fetch_result=True, auto_begin=False) -%} | ||
select TOP 0 * from ( | ||
{{ select_sql }} | ||
) as __dbt_sbq | ||
{% endcall %} | ||
{{ return(load_result('get_columns_in_query').table.columns | map(attribute='name') | list) }} | ||
{% endmacro %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikaelene, this is one macro we had to overwrite. perhaps this is the error you were seeing?
this PR is blocked by dbt-labs/dbt-adapter-tests#7
changes:
DROP SCHEMA ... CASCASE
to drop all views & tables on a given schema before dropping the schema itself. this was never an issue previously as it is only needed for the test suite and no materialization (that I know of) uses it.get_columns_in_query
because T-SQL does not supportLIMIT
.sqlserver__check_schema_exists()
:(database, schema)
to(information_schema, schema
)sqlserver__drop_schema
:(database_name, schema_name)
torelation
FYI (@mikaelene) many of these changes will also need to be propagated upstream to
dbt-sqlserver
. @NandanHegde15 and I are happy to help with that.